package com.hairline.controller;

import com.hairline.bean.User;
import com.hairline.bean.bo.DeleteFootprintBO;
import com.hairline.bean.vo.BaseRespVo;
import com.hairline.bean.vo.FootprintVO;
import com.hairline.service.WxFootprintService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {

    @Autowired
    WxFootprintService wxFootprintService;

    @RequestMapping("list")
    public BaseRespVo footprintList(Integer page, Integer size) {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipals().getPrimaryPrincipal();
        FootprintVO footprintVO = wxFootprintService.footprintList(page, size, user.getId());
        return BaseRespVo.ok(footprintVO);
    }

    @RequestMapping("delete")
    public BaseRespVo footprintDelete(@RequestBody DeleteFootprintBO deleteFootprintBO) {
        int code = wxFootprintService.footprintDelete(deleteFootprintBO.getId());
        if (code == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除失败,请重试");
    }

}
